﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;

namespace SharedGenomics.Workbench.Tests.Annotations
{
    [TestClass]
    public class AnnotationKeyDependencyGraphTests
    {
        [TestMethod]
        public void ShouldCreateGraph()
        {
            //create a graph with two edges n1 is a root node and n2 and n3 are its children
            AnnotationKey k1 = "key1";
            AnnotationKey k2 = "key2";
            AnnotationKey k3 = "key3";

            AnnotationKeyDependencyEdge e1 = new AnnotationKeyDependencyEdge(k1, k2);
            AnnotationKeyDependencyEdge e2 = new AnnotationKeyDependencyEdge(k1, k3);

            AnnotationKeyDependencyGraph graph = new AnnotationKeyDependencyGraph(new[] { e1, e2 });
            Assert.AreEqual(3, graph.NodeCount);

            //lookup each node and check its parent and children
            var n1 = graph.GetNodeForKey("key1");
            var n2 = graph.GetNodeForKey("key2");
            var n3 = graph.GetNodeForKey("key3");

            Assert.IsNull(n1.Parent);
            CollectionAssert.AreEqual(new[] { n2, n3 }, n1.Children.ToArray());

            Assert.AreEqual(n1, n2.Parent);
            Assert.AreEqual(0, n2.Children.Count());

            Assert.AreEqual(n1, n3.Parent);
            Assert.AreEqual(0, n3.Children.Count());
        }
    }
}
